package com.yixing.tech.system.dao;

import com.yixing.tech.common.base.BaseMongoDao;
import com.yixing.tech.common.enums.Status;
import com.yixing.tech.system.po.Tenant;
import com.yixing.tech.common.utils.DataUtil;
import com.yixing.tech.common.vo.s3.TenantVO;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author yixing tech
 * * @date 2022/1/5
 */
@Repository
public class TenantDao {


    @Resource
    private BaseMongoDao baseMongoDao;

    public void addChild(TenantVO vo) {

        Tenant parent = baseMongoDao.get(vo.getParentId(), Tenant.class);
        Tenant dict = DataUtil.o2o(vo, Tenant.class);
        dict.setStatus(Status.def.ordinal());
        dict = baseMongoDao.save(dict);
        List<Tenant> list = parent.getChildren();
        if (list == null) {
            list = new ArrayList<>();
            parent.setChildren(list);
        }
        Tenant child = new Tenant();
        child.setId(dict.getId());
        list.add(child);
        baseMongoDao.update(parent);
    }

}
